<template>
  <div id="aa" class="box">
      <router-link to="/examList/add">批量删除</router-link>
      <router-link to="/">添加题目</router-link>

       <table class="table">
         <thead>
           <tr>
             <th><input type="checkbox"/></th>
             <th scope="col">序号</th>
             <th scope="col">题目</th>
             <th scope="col">科目</th>
             <th scope="col">操作</th>
           </tr>
         </thead>
         <tbody>
           <tr v-model="examList" v-for="(item,index) in examList">
             <th><input type="checkbox"/></th>
             <th scope="row">{{index+1}}</th>
             <td>{{item.title}}</td>
             <td>{{item.course==1?'语文':item.course==2?'英语':item.course==3?'数学':item.course==4?'前端':'无信息'}}</td>
             <td><router-link to="">修改</router-link>   |   <a href="#" @click="delExam($event,item.id)">删除</a></td>
           </tr>
         </tbody>
       </table>

        <router-view/>
  </div>


</template>

<script>

  import Vue from 'vue';
  import $ from 'jquery';

  export default{
    name:"examList",
    data:()=>{
      return{
        examList:[]
      }
    },
    created:function(){
      this.list();
    },
    methods:{
      // 查看试题列表
       list:function(){
         var that = this;
         $.ajax({
           url:this.$store.state.localhost + "examList",
           type:"get",
           dataType:"json",
           success:(res)=>{
             console.log(res.data[0].title);
             that.examList = res.data;
           },
           error:(err)=>{
             console.log(err);
           }
         })
       },
       // 删除题库信息
       delExam:function(e,id){
          console.log(id);
           var that = this;
          if(confirm("确定要删除该数据吗？")){
            console.log("我点击了确定");
            $.ajax({
              url:that.$store.state.localhost + "delExam",
              type:"get",
              dataType:"json",
              data:{id:id},
              success:(res)=>{
                console.log(res);
                that.list();
              },
              error:(err)=>{
                console.log(err);
              }
            })
          }else{
            console.log("我点击了取消");
          }

       },
       // 修改试题信息
       editExam:function(){
          
       }
    }
  }
</script>

<style scoped="scoped">
  .box{
    width: 70%;
    margin: 50px auto;
  }
</style>
